/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  ZoneHuoDongMemberActivity.java   
 * @Package com.jiyi.activity.zone   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-6-19 下午4:47:25   
 * @version V1.0     
 */
package com.jiyi.activity.zone;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jiyi.adapter.CommonAdapter;
import com.jiyi.adapter.ViewHolder;
import com.jiyi.bean.zone.ZoneHaoYouBean;
import com.swift.base.ActivityBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: ZoneHuoDongMemberActivity
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-6-19 下午4:47:25
 * 
 */
public class ZoneHuoDongMemberActivity extends ActivityBase {

	@BindView(R.id.tvBack)
	TextView tvBack;
	@BindView(R.id.tvTitle)
	TextView tvTitle;
	@BindView(R.id.tvSearch)
	TextView tvSearch;

	/* activity控件 */
	@BindView(R.id.mainList)
	ListView mainList;
	@BindView(R.id.tvAllMember)
	TextView tvAllMember;

	// 数据适配器
	CommonAdapter<ZoneHaoYouBean> mAdapter;
	// 数据源
	List<ZoneHaoYouBean> dataList = new ArrayList<ZoneHaoYouBean>();
	// 是否刷新状态
	boolean isRefresh = false;
	// 加载进度圈
	Dialog dialog;
	//最大人数
	int max = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zone_huodong_member);
		ButterKnife.bind(this);
		init();
	}
	
	private void init() {
		getIntentData();
		setTop();
		setAdapter();
//		refresh();
//		initData();
	}
	
	private void getIntentData() {
		max = getIntent().getIntExtra("max", AppConfig.max_huodong);
		String userJson = getIntent().getStringExtra("user");
		List<ZoneHaoYouBean> temp = new Gson().fromJson(userJson, new TypeToken<List<ZoneHaoYouBean>>() {}.getType());
		if (temp != null && temp.size() >0) {
			dataList.clear();
			dataList.addAll(temp);
		}
		
		tvAllMember.setText("全部成员("+dataList.size()+"/"+max+")");
	}

	private void setTop() {
		tvBack.setText("");
		tvTitle.setText("活动成员");
		tvSearch.setVisibility(View.GONE);
	}
	
	private void setAdapter() {

		mAdapter = new CommonAdapter<ZoneHaoYouBean>(this, dataList,
				R.layout.item_zone_huodong_member) {
			@Override
			public void convert(final ViewHolder holder, final ZoneHaoYouBean t) {
				holder.setText(R.id.tvMemberName, t.getName());
				holder.setImage(R.id.ivLogo, t.getHead_path());
			}
		};
		mainList.setAdapter(mAdapter);
		mainList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ZoneHaoYouBean zoneHaoYouBean = (ZoneHaoYouBean) parent.getAdapter().getItem(position);
				Intent intent = new Intent(ZoneHuoDongMemberActivity.this,PersonInfoActivity.class);
				intent.putExtra("id", zoneHaoYouBean.getId());
				startActivity(intent);
			}
		});
	}
	
	private void initData() {

		dataList.clear();
		List<ZoneHaoYouBean> temp = new ArrayList<ZoneHaoYouBean>();
		for (int i = 0; i < 3; i++) {
			ZoneHaoYouBean ooo = new ZoneHaoYouBean();
			ooo.setHead_path("http://test.jyfire.cn/cs/images/hd02.png");
			ooo.setName("吉一成员" + i);
			ooo.setId(""+i);
			temp.add(ooo);
		}
		dataList.addAll(temp);
		tvAllMember.setText("全部成员("+dataList.size()+"/"+max+")");
		mAdapter.notifyDataSetChanged();
	}
	
	@OnClick({ R.id.tvBack })
	public void onClick(View view) {
		Intent intent = null;
		switch (view.getId()) {
		case R.id.tvBack:
			finish();
			break;
		default:
			break;
		}
	}
}
